/*
 * mirror of linkedin java
 */
package com.visikard.system;


/**
 * The Class VisikardApiUrls.
 * @author TuanNgo
 */
public final class VKregisterApiUrls {

//    /** The Constant API_URLS_FILE. */
	// TODO: check after crash ? move to / get from VisikardConfig
	private static final String API_SERVER_URL_HTTP = VKregisterConnects.getApiContextPathHttp();
	private static final String API_SERVER_URL_HTTPS = VKregisterConnects.getApiContextPathHttps();

//    /** The static logger. */
//    private static final String TAG = VisikardApiUrls.class.getCanonicalName();
    
    /** The Constant API_URLS_PLACEHOLDER_START. */
    private static final String API_URLS_PLACEHOLDER_START = "{";

    /** The Constant API_URLS_PLACEHOLDER_END. */
    private static final String API_URLS_PLACEHOLDER_END = "}";

//    static {
//        try {
//            linkedInApiUrls.load(VisikardApiUrls.class.getResourceAsStream(API_URLS_FILE));
//        } catch (IOException e) {
//        	LOG.log(Level.SEVERE, "An error occurred while loading urls.", e);
//        }
//    }

    /**
     * Instantiates a new linked in api urls.
     */
//    private VisikardApiUrls() {}

//    /**
//     * Encode url.
//     * 
//     * @param original the original
//     * @param encoding the encoding
//     * 
//     * @return the string
//     */
//    private static String encodeUrl(String original) {
//    	try {
//			return URLEncoder.encode(original, "UTF-8");
//		} catch (UnsupportedEncodingException e) {
//			// should never be here..
//			return original;
//		}
//    }

    public static String buildHttp(final String url) {
    	return buildHttp(url, null);
    }
    public static String buildHttp(final String url, final String[] pathVars) {
    	return build(url, pathVars, API_SERVER_URL_HTTP);
    }
    public static String buildHttps(final String url) {
    	return buildHttps(url, null);
    }
    public static String buildHttps(final String url, final String[] pathVars) {
    	return build(url, pathVars, API_SERVER_URL_HTTPS);
    }


    private static String build(final String url, final String[] pathVars, final String apiContextPath) {
    	// check
    	// TODO
    	String res = url;
	    if (pathVars != null && pathVars.length > 0) {
	    	// build path variable
	    	int i = 0;
	    	for (String var : pathVars) {
	        	// url encoding?
	        	// TODO
	
	    		// put actual variable to url
//	    		res = res.replaceAll(API_URLS_PLACEHOLDER_START + i + API_URLS_PLACEHOLDER_END, var);
	    		res = res.replace(API_URLS_PLACEHOLDER_START + i + API_URLS_PLACEHOLDER_END, var);
	    		i++;
	    	};
    	}

    	// return uri with prefix server context path
    	return apiContextPath + res;
    }

    /*----------------------------------------- account ------------------------------------------*/
    /** delete session */
    public static final String ACCOUNT_DELETE_SESSION = "session/delete/{0}/{1}";

    /*----------------------------------------- kard ------------------------------------------*/
    /** test kard url */
    public static final String KARD_GET_TEST = "kard/get/test/{0}/{1}";
    //...

    /*----------------------------------------- konnect ------------------------------------------*/
    /** test kard url */
    public static final String KONNECT_GET_TEST = "konnect/get/test/{0}/abc/{1}/cd/{1}";
    //...
}
